var baseUrl = "https://appsrv.sct360.com";
(function() {

    // register the interceptor as a service
    angular.module('myaop', []);
    angular.module('myaop').provider('myaop', function() {
        this.showLoading = true;
        this.$get = function($q) {
            var self = this;
            return {
                'setShowLoading': function(showLoading) {
                    self.showLoading = showLoading;
                },
                'getShowLoading': function() {
                    return self.showLoading;
                },
                // optional method
                'request': function(config) {
                    // do something on success
                    var defaultConfig = {
                        "method": "post"
                    };
                    return angular.extend(defaultConfig, config);
                },

                // optional method
                'requestError': function(rejection) {
                    // do something on error
                    return $q.reject(rejection);
                },

                // optional method
                'response': function(response) {
                    // do something on success
                    if(response.data.code !== "0") {
                        console.log(response.data);
                        return $q.reject(response);
                    }
                    return response;
                },

                // optional method
                'responseError': function(rejection) {
                    // do something on error
                    var errorMsg = '网络错误';
                    rejection.data = {code: rejection.status, error:errorMsg};
                    alert(errorMsg);
                    return $q.reject(rejection);
                }
            };
        }
    });

    angular.module('myaop').config(['$httpProvider', 'myaopProvider', function($httpProvider, myaopProvider) {
        $httpProvider.interceptors.push('myaop');
        // myaopProvider.showLoading = false;
    }]);

    var app = angular.module('district', ['myaop']);
    app.controller('districtCtrl', ['$scope', '$http', 'myaop', function($scope, $http, myaop) {
        $scope.shop_list = [];
        // &pageflag=1
        var url = baseUrl + "/service/storelist?appVersion=1.2.558&category_id=&latitude=50&longitude=50&radius=&reqnum=10&showInCommercialZone=Y&sort=01&storeAddressId=100000";
        $http({
            url: url,
            method: "get"
        }).then(function successCallback(response) {
            console.log(response.data);
            $scope.shop_list = response.data.data.SvcBody.shop_list;
            console.log(myaop.getShowLoading());
        }, function errorCallback(response) {
            // alert(response.)
            alert(response.data.error);
        });

    }]);

})();
